*****************************************************************
*********** Mining and violent competition in Africa ************
****** A.S. Rigterink, T. Ghani, J.S. Lozano, J.N. Shapiro ******
************ Replication of Table 2 of the main text ************

/*
0. Setting globals
1. Summary statistics
2. Outputting to Table

*/
*****************************************************************

clear all
version 17.0
set more off
cap log close

/*--------------------------------
------- 0. Setting globals -------
----------------------------------*/

*** Directory globals
*** NB: SET YOUR DIRECTORY HERE AND UNTEXT IF NOT RUNNING 0-Master.do
*global dir = ".\Replication_data\Stata"
*cd "$dir"

*** Subdirectories
global Do_files     "./Do"
global Data			"./Data"
global Results		"./Results"
global Tables 		"./Tables"

*** Scripts for spatially clustered standard errors
do "$Do_files/my_ols_spatial_HAC.do"
do "$Do_files/my_reg2hdfespatial.ado"

*** Load data
use "$Data/main.dta"


/*------------------------------------
------- 1. Summary statistics  -------
--------------------------------------*/

* Keeping only unique cells for one year
keep if year==2015
duplicates drop gid, force 

* Disregarding cells that mine another commodity
replace snl_dummy=0 if price_snl==0

**** Overall overlap between LSM and ASM
tab snl_dummy asm_voted

* Storing to matrix 
matrix comparison = J(3, 6, .)
sum snl_dummy if asm_voted==0 & snl_dummy==1
local number = r(N)
matrix comparison[3, 1]=`number'

sum snl_dummy if asm_voted==1 & snl_dummy==1
local number = r(N)
matrix comparison[2, 1]=`number'

sum snl_dummy if asm_voted==1 & snl_dummy==0
local number = r(N)
matrix comparison[2, 2]=`number'

sum snl_dummy if asm_voted==0 & snl_dummy==0
local number = r(N)
matrix comparison[3, 2]=`number'

*** Only LSM mines mining "suitable" minerals for ASM
tab snl_dummy asm_voted if snl_commodity=="cobalt" | snl_commodity=="coltan" | snl_commodity=="copper" | snl_commodity=="diamond" | snl_commodity=="gold" | snl_commodity=="tin" | snl_commodity=="tungsten"

* To matrix
sum snl_dummy if asm_voted==1 & snl_dummy==1 & (snl_commodity=="cobalt" | snl_commodity=="coltan" | snl_commodity=="copper" | snl_commodity=="diamond" | snl_commodity=="gold" | snl_commodity=="tin" | snl_commodity=="tungsten")
local number = r(N)
matrix comparison[2, 3]=`number'

sum snl_dummy if asm_voted==0 & snl_dummy==1 & (snl_commodity=="cobalt" | snl_commodity=="coltan" | snl_commodity=="copper" | snl_commodity=="diamond" | snl_commodity=="gold" | snl_commodity=="tin" | snl_commodity=="tungsten")
local number = r(N)
matrix comparison[3, 3]=`number'

*** Only LSM mines mining "unsuitable" modal mineral for ASM
tab snl_dummy asm_voted if snl_commodity!="cobalt" & snl_commodity!="coltan" & snl_commodity!="copper" & snl_commodity!="diamond" & snl_commodity!="gold" & snl_commodity!="tin" & snl_commodity!="tungsten"

* To matrix
sum snl_dummy if asm_voted==1 & snl_dummy==1 & snl_commodity!="cobalt" & snl_commodity!="coltan" & snl_commodity!="copper" & snl_commodity!="diamond" & snl_commodity!="gold" & snl_commodity!="tin" & snl_commodity!="tungsten"
local number = r(N)
matrix comparison[2, 4]=`number'

sum snl_dummy if asm_voted==0 & snl_dummy==1 & snl_commodity!="cobalt" & snl_commodity!="coltan" & snl_commodity!="copper" & snl_commodity!="diamond" & snl_commodity!="gold" & snl_commodity!="tin" & snl_commodity!="tungsten"
local number = r(N)
matrix comparison[3, 4]=`number'

*** LSM mine for mineral "suitable" for ASM present
tab snl_dummy asm_voted if snl_gold>0 | snl_diamond>0 | snl_copper>0 | snl_cobalt>0 | snl_tungsten>0 | snl_tin>0 | snl_coltan>0

* To matrix
sum snl_dummy if asm_voted==1 & snl_dummy==1 & (snl_gold>0 | snl_diamond>0 | snl_copper>0 | snl_cobalt>0 | snl_tungsten>0 | snl_tin>0 | snl_coltan>0)
local number = r(N)
matrix comparison[2, 5]=`number'

sum snl_dummy if asm_voted==0 & snl_dummy==1 & (snl_gold>0 | snl_diamond>0 | snl_copper>0 | snl_cobalt>0 | snl_tungsten>0 | snl_tin>0 | snl_coltan>0)
local number = r(N)
matrix comparison[3, 5]=`number'

*** No LSM mine for mineral "suitable" for ASM present
tab snl_dummy asm_voted if snl_gold==0 & snl_diamond==0 & snl_copper==0 & snl_cobalt==0 & snl_tungsten==0 & snl_tin==0 & snl_coltan==0

* To matrix 
sum snl_dummy if asm_voted==1 & snl_dummy==1 & snl_gold==0 & snl_diamond==0 & snl_copper==0 & snl_cobalt==0 & snl_tungsten==0 & snl_tin==0 & snl_coltan==0
local number = r(N)
matrix comparison[2, 6]=`number'

sum snl_dummy if asm_voted==0 & snl_dummy==1 & snl_gold==0 & snl_diamond==0 & snl_copper==0 & snl_cobalt==0 & snl_tungsten==0 & snl_tin==0 & snl_coltan==0
local number = r(N)
matrix comparison[3, 6]=`number'

/*-------------------------------------
------- 2. Outputting to Table  -------
---------------------------------------*/

clear
svmat comparison

gen asm = ""
replace asm = "suitable?" if _n==1
replace asm = "Yes" if _n==2
replace asm = "No" if _n==3

order asm
label var asm "ASM"

label var comparison1 "LSM"
label var comparison2 "present?"

for var comparison?: tostring X, replace force

replace comparison1 = "Yes" if _n==1
replace comparison2 = "No" if _n==1 

label var comparison3 "LSM modal mineral"
label var comparison4 "ASM suitable?"

label var comparison5 "LSM of ASM suitable"
label var comparison6 "mineral present?"

replace comparison3 = "Yes" if _n==1
replace comparison4 = "No" if _n==1 
replace comparison5 = "Yes" if _n==1
replace comparison6 = "No" if _n==1 

texsave using "$Tables/Table_LSMASMoverlap.tex", replace hlines(1) title("Overlap between presence LSM and ASM suitability") label(tab:asm_lsm_overlap) varlabels location(h) nofix align(c | c c | c c | c c ) frag

